package com.ruoyi.hr.controller.hr.welfare;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.hr.service.welfare.WelfareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zeo
 * @explain 福利管理模块
 * @date 2019/12/18 8:30
 */
@Controller
@RequestMapping("/welfare")
public class WelfareController extends BaseController {

    @Autowired
    WelfareService welfareService;

    private String prefix = "hr/welfare";

    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String user() {
        return prefix + "/welfare";
    }

    /**
     * 欢迎
     */
    @GetMapping("/welcome")
    public String welcome() {
        return prefix + "/welcome";
    }

    /**
     * 加载部门列表树
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData() {
        List<Ztree> ztrees = new ArrayList<Ztree>();
        Ztree ztree[] = {
                new Ztree((long) 100, (long) 0, "福利地区配置(全局)(3)", "福利地区配置(全局)(3)"),
                new Ztree((long) 101, (long) 100, "福利地区配置", "福利地区配置"),
                new Ztree((long) 102, (long) 100, "福利类型", "福利类型"),
                new Ztree((long) 103, (long) 100, "福利地区参数配置", "福利地区参数配置"),

                new Ztree((long) 104, (long) 0, "福利计算配置(区域)(2)", "福利计算配置(区域)(2)"),
                new Ztree((long) 105, (long) 104, "福利基数", "福利基数"),
                new Ztree((long) 106, (long) 104, "福利计算项目", "福利计算项目"),

                new Ztree((long) 107, (long) 0, "福利信息(1)", "福利信息(1)"),
                new Ztree((long) 108, (long) 107, "福利信息", "福利信息"),

                new Ztree((long) 109, (long) 0, "福利开启(2)", "福利开启(2)"),
                new Ztree((long) 110, (long) 109, "福利开启", "福利开启"),
                new Ztree((long) 111, (long) 109, "福利开启历史", "福利开启历史"),

                new Ztree((long) 112, (long) 0, "特殊人员公积金登记(1)", "特殊人员公积金登记(1)"),
                new Ztree((long) 113, (long) 112, "特殊人员公积金登记", "特殊人员公积金登记"),

                new Ztree((long) 114, (long) 0, "福利变动(2)", "福利变动(2)"),
                new Ztree((long) 115, (long) 114, "福利缴纳变动", "福利缴纳变动"),
                new Ztree((long) 116, (long) 114, "福利缴纳变动历史", "福利缴纳变动历史"),

                new Ztree((long) 117, (long) 0, "福利基数调整(4)", "福利基数调整(4)"),
                new Ztree((long) 118, (long) 117, "社保基数调整", "社保基数调整"),
                new Ztree((long) 119, (long) 117, "社保基数调整历史", "社保基数调整历史"),
                new Ztree((long) 120, (long) 117, "公积金基数调整", "公积金基数调整"),
                new Ztree((long) 121, (long) 117, "公积金基数调整历史", "公积金基数调整历史"),

                new Ztree((long) 122, (long) 0, "福利补缴(2)", "福利补缴(2)"),
                new Ztree((long) 123, (long) 122, "福利补缴登记", "福利补缴登记"),
                new Ztree((long) 124, (long) 122, "福利补缴历史", "福利补缴历史"),

                new Ztree((long) 125, (long) 0, "福利数据导入(1)", "福利数据导入(1)"),
                new Ztree((long) 126, (long) 125, "福利数据导入", "福利数据导入"),

                new Ztree((long) 127, (long) 0, "福利计算(2)", "福利计算(2)"),
                new Ztree((long) 128, (long) 127, "月福利计算", "月福利计算"),
                new Ztree((long) 129, (long) 127, "月福利历史", "月福利历史")
        };
        for (int i = 0; i < ztree.length; i++) {
            ztrees.add(ztree[i]);
        }
        return ztrees;
    }

    @ResponseBody
    @RequestMapping("changeIslock")
    public AjaxResult changeIslock(String id, String islock, String table) {
        table = getTable(table);
        return toAjax(welfareService.updateIslock(id, islock, table));
    }

    @ResponseBody
    @RequestMapping("changeDisabled")
    public AjaxResult changeDisabled(String id, String isDisabled, String table) {
        table = getTable(table);
        return toAjax(welfareService.updateIsDisabled(id, isDisabled, table));
    }

    private String getTable(String table) {
        if ("福利基数".equals(table)) {
            return "CCD_BENEFITBASE";
        }else if("福利类型".equals(table)){
            return "CCD_BENEFITTYPE";
        }
        return "";
    }
}
